﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using PresentationNamespace;

namespace WPF
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window, IStackView
    {
        public string stackState
        {

            set
            {
                stackStateTextBox.Text = value;
            }
        }
        public string addItemField
        {
            get
            {
                return addNewItemTextBox.Text;
            }
            set
            {
                addNewItemTextBox.Text = value;
            }
        }
        public string gotItemField
        {
            set
            {
                getItemTextBox.Text = value;
            }
        }
        public string errorMessage
        {
            set
            {
                errorMessageLabel.Content = value;
            }
        }
        public bool isErrorMessageVisible
        {
            get
            {
                if (errorMessageLabel.Visibility == System.Windows.Visibility.Visible)
                    return true;
                else
                    return false;
            }
            set
            {
                if(value == true)
                    errorMessageLabel.Visibility = System.Windows.Visibility.Visible;
                else
                    errorMessageLabel.Visibility = System.Windows.Visibility.Hidden;
            }
        }
        public string logWindow
        {
            set
            {
                logTextBox.Text = value;
            }
        }
        public bool isLogPanelVisible
        {
            get
            {
                if (logTextBox.Visibility == System.Windows.Visibility.Visible)
                    return true;
                else
                    return false;
            }
            set
            {
                if (value == true)
                {
                    logTextBox.Visibility = System.Windows.Visibility.Visible;
                    saveLogButton.Visibility = System.Windows.Visibility.Visible;
                    textRadioButton.Visibility = System.Windows.Visibility.Visible;
                    htmlRadioButton.Visibility = System.Windows.Visibility.Visible;
                }
                else
                {
                    logTextBox.Visibility = System.Windows.Visibility.Hidden;
                    saveLogButton.Visibility = System.Windows.Visibility.Hidden;
                    textRadioButton.Visibility = System.Windows.Visibility.Hidden;
                    htmlRadioButton.Visibility = System.Windows.Visibility.Hidden;
                }
            }
        }
        public TypeLog typeLog
        {
            get
            {
                if (textRadioButton.IsChecked == false)
                {
                    return TypeLog.Text;
                }
                else
                {
                    return TypeLog.Html;
                }
            }
            set
            {
                if (value == TypeLog.Text)
                {
                    textRadioButton.IsChecked = true;
                    htmlRadioButton.IsChecked = false;
                }
                else
                {
                    htmlRadioButton.IsChecked = true;
                    textRadioButton.IsChecked = false;
                }
            }
        }

        public event Action OnGetElementClick;
        public event Action OnAddElementClick;
        public event Action OnShowLogClick;
        public event Action OnSaveLogClick;
        public event Action OnChangeTypeLogToText;
        public event Action OnChangeTypeLogToHtml;

        public MainWindow()
        {
            InitializeComponent();
            new StackPresenter((IStackView)this);
        }

        private void addNewItemButton_Click(object sender, RoutedEventArgs e)
        {
            OnAddElementClick();
        }

        private void getNewItemButton_Click(object sender, RoutedEventArgs e)
        {
            OnGetElementClick();
        }

        private void showLogCheckBox_Checked(object sender, RoutedEventArgs e)
        {
            OnShowLogClick();
        }

        private void showLogCheckBox_Unchecked(object sender, RoutedEventArgs e)
        {
            OnShowLogClick();
        }

        private void saveLogButton_Click(object sender, RoutedEventArgs e)
        {
            OnSaveLogClick();
        }

        private void textRadioButton_Click(object sender, RoutedEventArgs e)
        {
            OnChangeTypeLogToText();
        }

        private void htmlRadioButton_Click(object sender, RoutedEventArgs e)
        {
            OnChangeTypeLogToHtml();
        }
    }
}
